<?php
class vtnsSlide 
{
	public static function render($t = 5000)
	{
		$sf_culture = sfContext::getInstance()->getUser()->getCulture();
		$_html = '';
		$category = Doctrine_Core::getTable("VTNSCmsCategory")->findOneByAlias("slide");
		$q = Doctrine_Query::create()
				->from("VTNSCms c")
				->where("c.cms_category_id = ?", $category->cms_category_id)
				->orderBy("c.created_at");
		$index = 0;
		foreach ($q->fetchArray() as $cms)
		{
			$index ++;
			$_html .= '
				<div class="vtns_slide '.(($index == 1)?'slide_current':'').'">
					<img src="/uploads/cms/'.$cms['picture'].'" style="width:100%;" />
					<p>'.(($sf_culture == "vi")?$cms['name_vi']:$cms['name']).'
					</br>
					<em>'.(($sf_culture == "vi")?$cms['description_vi']:$cms['description']).'</em>
					</p>
				</div>
			';
		}
		
		// JS
		$_html .= '
			<script>
				$(document).ready(function()
				{
					var t = setInterval(function() {
						$(".slide_current").animate({opacity:0.5}, 500, function()
						{
							if ($(this).next().hasClass("vtns_slide"))
							{
								$(this).next().animate({opacity:1}, 1000, function()
								{
									$(this).addClass("slide_current");
								});
							} else {
								$(".vtns_slide:first").animate({opacity:1}, 1000, function()
								{
									$(this).addClass("slide_current");
								});
							}
							$(this).css("opacity", 0);
							$(this).removeClass("slide_current");
						});
					}, '.$t.');
				});
			</script>
		';
		
		echo $_html;
	}
}
?>